import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


/* Implement FindFact which returns just a FactAddressValue or null */
/* TBD Add size method to PrimitiveValue */

class AptitudPanel extends JPanel {

    /**
     * 
     */
    private static final long serialVersionUID = -1098064686220767426L;

    /**
     * 
     */
    

    JLabel dLabel;

    JComboBox flexibilidad ;
    JComboBox capaciadad_superacion ;
    JComboBox optimismo ;
    JComboBox iniciativa ;
    JComboBox motivacion ;

    
    JButton nextButton;
    JButton prevButton;
    JPanel choicesPanel;
    ButtonGroup choicesButtons;

	
	PrintWriter writer;

    public AptitudPanel()  {


        /* ================================ */
        /* Create a new JFrame container. */
        /* ================================ */

        final JFrame jfrm = new JFrame("TestVocacionalDemo");

        /* ============================= */
        /* Specify FlowLayout manager. */
        /* ============================= */
        
        
        jfrm.getContentPane().setLayout(new GridLayout(1, 1));

        /* ================================= */
        /* Give the frame an initial size. */
        /* ================================= */

        jfrm.setSize(750, 300);
        jfrm.setLocation(200, 100);

        /* ============================================================= */
        /* Terminate the program when the user closes the application. */
        /* ============================================================= */

        jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        /* =========================== */
        /* Create the display panel. */
        /* =========================== */

        JPanel displayPanel = new JPanel();
        JLabel displayLabel = new JLabel();
        displayPanel.add(displayLabel);

        /* =========================== */
        /* Create the choices panel. */
        /* =========================== */

        choicesPanel = new JPanel();
        choicesPanel.setBorder(BorderFactory.createTitledBorder("Aptitudes del alumno"));

        choicesPanel.setSize(400, 400);
        choicesPanel.setSize(getMaximumSize());
        choicesPanel.setLayout(new BoxLayout(choicesPanel, BoxLayout.Y_AXIS));
        
        dLabel = new JLabel("Flexibilidad");
        dLabel.setSize(getPreferredSize());
        choicesPanel.add(dLabel);
        
        flexibilidad = new JComboBox();
        flexibilidad.addItem("alto");
        flexibilidad.addItem("medio");
        flexibilidad.addItem("bajo");
       

        choicesPanel.add(flexibilidad);

        dLabel = new JLabel("Capacidad de superacion");
        choicesPanel.add(dLabel);
        capaciadad_superacion = new JComboBox();
        capaciadad_superacion.addItem("alto");
        capaciadad_superacion.addItem("medio");
        capaciadad_superacion.addItem("bajo");
        choicesPanel.add(capaciadad_superacion);

        dLabel = new JLabel("Optimismo");
        choicesPanel.add(dLabel);
        optimismo   = new JComboBox();
        optimismo.addItem("alto");
        optimismo.addItem("medio");
        optimismo.addItem("bajo");
        choicesPanel.add(optimismo);

        dLabel = new JLabel("Iniciativa");
        choicesPanel.add(dLabel);
        iniciativa   = new JComboBox();
        iniciativa.addItem("alto");
        iniciativa.addItem("medio");
        iniciativa.addItem("bajo");
        choicesPanel.add(iniciativa);

        dLabel = new JLabel("Motivacion");
        choicesPanel.add(dLabel);
        motivacion  = new JComboBox();
        motivacion.addItem("alto");
        motivacion.addItem("medio");
        motivacion.addItem("bajo");
        choicesPanel.add(motivacion);

     
        /* =========================== */
        /* Create the buttons panel. */
        /* =========================== */

        
        try {
            writer = new PrintWriter("factsAptitud.clp", "UTF-8");

        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (UnsupportedEncodingException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        JPanel buttonPanel = new JPanel();



        nextButton = new JButton("Next");
        nextButton.setActionCommand("Next");
        choicesPanel.add(nextButton);
        nextButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                HabilidadPanel habilidadPanel = new HabilidadPanel();
				
				
				writer.println("(deffacts caso_4 " );
				writer.println("	(aptitud " );
				writer.println("		(flexibilidad "+flexibilidad.getSelectedItem().toString()+")");
				writer.println("		(capaciadad_superacion "+capaciadad_superacion.getSelectedItem().toString()+")");
				writer.println("		(optimismo "+optimismo.getSelectedItem().toString()+")" );
				writer.println("		(iniciativa "+iniciativa.getSelectedItem().toString()+")");
				writer.println("		(motivacion "+motivacion.getSelectedItem().toString()+")))");
				writer.close();
				
			
                habilidadPanel.setVisible(true);
                jfrm.setVisible(false);

				

            }
        });

        /* ===================================== */
        /* Add the panels to the content pane. */
        /* ===================================== */

        jfrm.getContentPane().add(displayPanel);
        jfrm.getContentPane().add(choicesPanel);
        jfrm.getContentPane().add(buttonPanel);

        /* ==================== */
        /* Display the frame. */
        /* ==================== */

        jfrm.setVisible(true);
        displayLabel.setText("Run clips file");
        /* ================================== */
        /* Get the current state of the UI. */
        /* ================================== */

    }


}
